<?php
/**
 * Created by SNWAY.
 * User: w
 * Date: 2017/7/25
 * Time: 12:46
 */

namespace app\index\controller;
use app\index\Controller;
use think\Db;
use think\Exception;
use think\Session;

class SmsSend
{
    /**
     * $code 要发送的验证码信息
     * $sms_code  短信模板
     * Date: 2017/7/25
     * Time: 12:46
     */
    public function index($sms_code,$phone,$data='')
    {
        $code =  rand(1000,9999);
        if($sms_code){
            if($sms_code =='SMS_79150041'||$sms_code =='SMS_79010037'||$sms_code =='SMS_79080049'||$sms_code =='SMS_94520048'||$sms_code =='SMS_79150041'){
                //更换手机号,修改密码，重置密码 发送短信验证码
                $param = array( "code"=>$code);

            }elseif($sms_code =='SMS_79040038'){
                //发送验证码，拼接字符串
                $param = array(
                    "code"=>$code,
                    "n"=>'5',
                    "ProviderName"=>'黎明',
                    "service"=> servicetel(),
                    );
            }elseif ($sms_code=="SMS_96870035"){
                $param = array( "code"=>$code);
            }elseif ($sms_code=="SMS_102375088"){
                $param = array(
                    'providerName'=>$data['providerName'],
                    'memberName'=>$data['memberName'],
                    'password'    => $data['password'],
                    'sign'=> $data['sign'],
                    'service'  =>servicetel(),
                );
            }
        }
//        $data = array(
//            //短信模板代码
//             'sms_code' =>'SMS_79150041',
//            //短信发送号码
//             'phone' =>'15210009576',
//            //短信发送模板字段
//             'param' => array( "code"=>"3333",),
//        );
        $response = sendSms(
            $sms_code,//短信模板编号
            $phone,//短信接收者
            $param//短信模板中字段的值
        );
        $response =json_decode( json_encode( $response),true);
        if($response['Code'] == 'OK'){
            Session::set($phone.'_smsCode',$code);
            Session::set($phone.'_sendTime',time());
            $res['code'] = $response['Code'];
            $res['msg'] = '发送成功';
        }else{
            $res['code'] = $response['Code'];
            $res['msg'] = '发送失败';
        }
         // $res['msg'] = $response['Message'];
           return $res;
    }

    //支付短信提醒
    public function pay($code='',$sms_code='',$phone='')
    {
//        $code =  rand(1000,9999);
        if($sms_code){
            //发送验证码，拼接字符串
            if ($sms_code=="SMS_79495025")
            {
                $param = array(
                'memberName'=>$code['memberName'],
                'dateTime'  =>aTime(),
                'providerName'=>$code['providerName'],
                    'payType' => $code['payType']
                );
            }
            elseif($sms_code=="SMS_79490017")
            {
                $param = array(
                    'memberName'=>$code['memberName'],
                    'providerName'=>$code['providerName'],
                    'orderNo'  =>$code['orderNo'],
                );
            }

            elseif($sms_code=="SMS_99570032")
            {
                $param = array(
                    'memberName'=>$code['memberName'],
                    'dateTime'    => aTime(),
                    'change'=> $code['change'],
                    'balance'=>$code['balance'],
                    'service'  =>servicetel(),
                );
            }
            elseif($sms_code=="SMS_102375088")
            {
                $param =$code;
            }
            elseif($sms_code=="SMS_79730006")
            {
                $param = array(
                    'memberName'=> $code['memberName'],
                    'providerName'=>$code['providerName'],
                    'orderNo'     =>$code['orderNo'],
                    'service'  => servicetel(),
                );
            }
        }

        $response = sendSms(
            $sms_code,//短信模板编号
            $phone,//短信接收者
            $param//短信模板中字段的值
        );
        $response =json_decode( json_encode( $response),true);
        if($response['Code'] == 'OK'){
            Session::set($phone.'_smsCode',$code);
            Session::set($phone.'_sendTime',time());
            $res['code'] = $response['Code'];
            $res['msg'] = '发送成功';
        }else{
            $res['code'] = $response['Code'];
            $res['msg'] = '发送失败';
        }
      //  $res['msg'] = $response['Message'];

        return $res;
    }
}